package com.ah.ues;

/**
 * JsonResult
 *
 */
public class JsonResult<T> {
    public static final int SUCCESS = 0;

    public int code;
    public String msg;
    public T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public JsonResult() {
    }

    public JsonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public JsonResult(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public static <T> JsonResult<T> success(T data, String msg) {
        JsonResult<T> result = new JsonResult<>(SUCCESS, data);
        result.setMsg(msg);
        return result;
    }

    public static <T> JsonResult<T> error(String msg) {
        return new JsonResult<>(500, msg);
    }

}
